<%@include file="/WEB-INF/common/taglibs.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/datatable-query.js"></script>
<script>
$(document).ready(function(){
	$("form.form-horizontal.seperator[method='post']").validate();
});
	
	
 </script>
<div class="row-fluid">

	<div class="span12">

		<div class="page-header">
			<h4>Geo Zone </h4>
		</div>

<form class="form-horizontal seperator" method="post">
<!--name --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3" for="name">Name :</label><input class="span4" id="name" name="name"   type="text" value="${entity.name}" /></div></div></div>



 <div class="form-row row-fluid">
				<div class="span12">
					<div class="row-fluid">
						<div class="form-actions">
							<div class="span3"></div>
							<div class="span4 controls">
								<button type="submit" class="btn btn-info marginR10">Save
									changes</button>
								<button class="btn btn-danger">Cancel</button>
							</div>
						</div>
					</div>
				</div>
			</div>
</form>
		
		 
<c:if test="${entity.id ne null}">
	<div class="box gradient">
	 
		<div class="title">
				<h4>
				<span>Geo Zone Record </span> <span class="box-form right"> </span>
				
				<span class="box-form right geoZoneRecord_bar"><a href="#" class="btn btn-mini addGeoZoneRecord">Add Geo Zone Record</a></span>
 				</h4>
 				<a href="#" class="minimize"> </a>
			</div>
		 <div class="content scrollable clearfix">
		<table class="table table-bordered table-vertical-centre geoZoneRecordTable">
			<thead>
				<tr>
					<th><a class="select_all"><span class="icomoon-icon-checkmark-2"></span></a></th>
<th>Country </th>
<th>Country Zone </th>

 					<th>Action</th>
				</tr>
			</thead>
		</table>
		</div>
	 
</div>
 





<script>
 
 

$(document).ready(function(){
	$('select[name=countryId]').change(function(){
		var countryId = $('select[name=countryId]').val();
		$.ajax({
			url : "${ctx}/admin/country-zone/"+countryId+"/list/",
			type : "GET",
			dataType : "json",
			success : function(data){		
				if(data && data.state && (data.state.indexOf("ERROR") != -1)){
					johnny.error(data.message);
					return;
				}else{

  				var zone = $('select[name=countryZoneId]');
  				zone.empty();
				$(data).each(function(step,value){
					$('<option>').val(value.id).text(value.name).appendTo(zone);
 				}); 
				zone.uniform();			
  				}
				
			}
		});
		 
 	});
	
	
	
	
	
	
	
	
	
	
	
	
	
	var del = {
			id : 'geoZoneRecordDel',
			text  : 'Del',
			domain : "Geo Zone Record",
			operation : "Del",
			url : "${ctx}/admin/geo-zone-record/del/",
			selector : ".geoZoneRecord_bar",
			selects  : $('.geoZoneRecordTable'),
	  
	};
	johnny.tableBtn(del);
	
 	
	
	$('.addGeoZoneRecord').click(function(){
		
		
		
		
	$("#geoZoneRecordDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type=hidden]").each(function(step,value){
	 									$(value).val("");
	 							});
	
	
	var country = $('select[name=countryId]');
	country.val(country.find("option:first").val());
	country.trigger('change');
	 $("#geoZoneRecordDiv input[name='action']").val("${ctx}/admin/geo-zone-record/create/");
 	 $("#geoZoneRecordDiv").modal('show');
  });
	
	  $(document).delegate('.geoZoneRecordTable .icomoon-icon-pencil', 'click', function(event) {
		  
		  	var id = $(this).parent().attr("dataid");
			$.ajax({
				url : "${ctx}/admin/geo-zone-record/"+id+"/edit/",
				type : "GET",
				dataType : "json",
				success : function(data){		
					if(data && data.state && (data.state.indexOf("ERROR") != -1)){
						johnny.error(data.message);
						return;
					}else{
							var entity = data.entity;
 							$("#geoZoneRecordDiv").find("div.modal-body").find("input,select,textarea,checkbox").not("[name=action],[type=hidden]").each(function(step,value){
									var name = $(value).attr("name");
 									if (entity[name]){
										$(value).val(entity[name]);
 										$(value).uniform();
 									}else if (name.match(/Id$/)){
										var pro = name.substring(0,name.length-2);
										if (entity[pro] &&entity[pro].id){
											$(value).val(entity[pro].id);
	 										$(value).uniform();
 										}
 									
									}
									else{
 										$(value).val("");
									}
								
							});
							
 							$('select[name=countryId]').trigger('change');
 							
 							setTimeout(function(){
  								var zone = $('select[name=countryZoneId]');
 								zone.val(entity.countryZone.id);
  	 							$("#geoZoneRecordDiv input[name='action']").val("${ctx}/admin/geo-zone-record/"+id+"/edit/");
 	     	    				$("#geoZoneRecordDiv").modal('show');
 	     	    				zone.uniform();
 	     	    				
 							},500);
 							
							
  					}
				}
			});		  
 
	     
	    });
	var recordColumn = ['', 'country','countryZone'];
	
	 $('.geoZoneRecordTable').dataTable({
		"bLengthChange" : true,
		"aoColumnDefs" : [ {
			'bSortable' : false,
			'aTargets' : [0,3 ]
		} ],
 		"sAjaxSource" : '${ctx}/admin/geo-zone-record/${entity.id}/',
		"createQueryData" : function (aoData){
				return	johnny.initQueryData(aoData, recordColumn);
		},
		"createResult" : function (json, echo){
 			var dataArray = new Array();
			for ( var i = 0; i < json.result.length; i++) {
				var subArray = new Array();
				var value = johnny.getForSelect(json.result[i].id);
				subArray.push(value);
subArray.push(json.result[i].country.name)
subArray.push(json.result[i].countryZone.name)

   				var conf = [{
					link : 'javascript:void(1)',
					dataId : json.result[i].id,
					text : 'edit',
					css  : 'icomoon-icon-pencil'
				} 
				
				];
				subArray.push(johnny.getGridLink(conf)); 
  				dataArray.push(subArray);
			}
			return {
				sEcho : echo,
				iTotalRecords : json.totalCount,
				iTotalDisplayRecords : json.totalCount,
				aaData : dataArray
			};
		}		
	});
	 
	
	
	
	
});


</script>





<div id="geoZoneRecordDiv" class="modal hide fade"  selector=".geoZoneRecordTable" style="display: none; ">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">
			<span class="icon12 minia-icon-close"></span>
		</button>
		<h3>	Geo Zone Record  </h3>
	</div>
 
	<div class="modal-body">
  						<input type="hidden" name="action" >
 						<input type="hidden" name="geoZoneId" value="${entity.id}" >
<!--country --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3">Country :</label><div class="span9 controls"><select name="countryId"><c:if test="${not empty countries}"><c:forEach var="single" items="${countries}"><option value="${single.id}">${single.name}</option></c:forEach></c:if></select></div></div></div></div>
<!--countryZone --><div class="form-row row-fluid"><div class="span12"><div class="row-fluid"><label class="form-label span3">Country Zone :</label><div class="span9 controls"><select name="countryZoneId"><c:if test="${not empty countryZones}"><c:forEach var="single" items="${countryZones}"><option value="${single.id}">${single.name}</option></c:forEach></c:if></select></div></div></div></div>

						 
	</div>
	 
	<div class="modal-footer">
		<a href="#" class="btn" data-dismiss="modal">Close</a>
		<a href="#" class="btn btn-primary modal-submit">Save changes</a>
	</div>

</div>

</c:if>	



		

	</div>
	<!-- End .span12 -->

</div>
<!-- End .row-fluid --> 

